﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>商户账目</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>

    <script>
        $(function () {
            Mer();//获取商户列表到下拉框
        });
        var Mer;//商户
        var diplayText;//选中行的数据
        //获取商户
        function Mer() {
            var grid = $('#MerName').combogrid({
                panelWidth: 500,
                idField: 'MerID',
                textField: 'MerName',
                url: '/MerAccount/getMer',
                method: 'post',
                pageSize: 5,
                pageList: [5],
                pagination: true,
                rownumbers: true,
                fitColumns: true,
                columns: [[
                    { field: 'MerID', title: '商户ID', width: 80, align: 'center', hidden: 'true' },
                    { field: 'MerName', title: '商户名称', width: 80, align: 'center' },
                    { field: 'MerTxt', title: '商户介绍', width: 120, align: 'center' },
                    { field: 'MerAdr', title: '商户地址', width: 80, align: 'center' },
                    { field: 'MerCall', title: '商户联系电话', width: 80, align: 'center' }
                ]],
                onSelect: function (index, row) {
                    diplayText = row[grid.combogrid('options').textField];
                    Mer = $('#MerName').combogrid("getValue");//获取商户
                    //加载对应的商户账目
                    initTable(Mer);
                    document.getElementById("sleaccount").style.display = "block";
                },
                onLoadSuccess: function () {
                    //分页后判断下是否有选中的数据行，combogrid会依据上一次选中的值进行初始化，选中datagrid数据行和设置显示值
                    if (!grid.combogrid('grid').datagrid('getSelected'))//不在当前页
                    {
                        $('#MerName').combogrid("setValue", diplayText);
                    }
                }
            });
        }

        var Common = {
            /**
             * 格式化日期（不含时间）
             */
            formatterDate: function (date) {
                if (date == undefined) {
                    return "";
                }
                /*json格式时间转js时间格式*/
                date = date.substr(1, date.length - 2);
                var obj = eval('(' + "{Date: new " + date + "}" + ')');
                var date = obj["Date"];
                if (date.getFullYear() < 1900) {
                    return "";
                }

                var datetime = date.getFullYear()
                        + "-"// "年"
                        + ((date.getMonth() + 1) > 10 ? (date.getMonth() + 1) : "0"
                                + (date.getMonth() + 1))
                        + "-"// "月"
                        + (date.getDate() < 10 ? "0" + date.getDate() : date
                                .getDate());
                return datetime;
            }
        }

        function initTable(item) {
            $('#load').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/MerAccount/getgrid?MerID=' + item + "&MerAccType=&MerAccDate=",
                sortName: 'MerAccID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'MerAccID',
                pageSize: 10,
                singleSelect: true,
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'MerAccID', title: '账目编号', width: 100, sortable: true, align: 'center' },
                    { field: 'MerName', title: '商户名称', width: 200, sortable: true, align: 'center' },
                    {
                        field: 'MerAccDate', title: "账目日期", width: 150, sortable: true, align: 'center',
                        formatter: function (value) {
                            if (typeof (value) != 'undefined') {
                                var data = value.toString();
                                var str = data.substring(0, 4) + '-' + data.substring(4, 6) + '-' + data.substring(6, 8);
                            }
                            
                            return str;
                        }
                    },
                    {
                        field: 'MerAccTime', title: "生成时间", width: 150, sortable: true, align: 'center', formatter: function (value) {
                            if (typeof (value) != 'undefined')
                            {
                                var data = value.toString();
                                var str = data.substring(0, 2) + ':' + data.substring(2, 4) + ':' + data.substring(4, 6);
                            }
                            return str;
                        }
                    },
                    {
                        field: 'MerAccType', title: "流水类型", width: 150, sortable: true, align: 'center', formatter: function (t) {
                            if (t == 0) {
                                return '金额流水';
                            }
                            else if (t == 1) {
                                return '第三方流水';
                            }
                            else if(t==2) {
                                return '积分流水';
                            }
                            else if (t == 4)
                            {
                                return '企业流水';
                            }
                        },
                    },
                    { field: 'MerAccInt', title: '当日收入', width: 150, sortable: true, align: 'center' },
                    { field: 'MerAccOut', title: '当日支出', width: 150, sortable: true, align: 'center' }
                ]],
                toolbar: '#tb'
            });
        }

        

        //检索
        function Search() {
            MerAccType = $("#MerAccType").combobox('getValue'),
            MerAccDate = $("#MerAccDate").datebox('getValue'),
            //alert(Mer+MerAccType + MerAccDate)
            $("#load").datagrid({
                url: '/MerAccount/getgrid?MerID=' + Mer + "&MerAccType=" + MerAccType + "&MerAccDate=" + MerAccDate,
            });
        }

        ////清空文本框中的值
        function ClearText() {
            $("#MerAccType").val(""),
            $("#MerAccDate").val(""),
            $("#MerName").val("")
        }
    </script>


</head>
<body style="padding: 0;">
    <!--表格加载S-->
    <div>
        <table id="load" style="width: auto;"></table>
    </div>
    <!--表格加载E-->

    <!--工具栏S-->
    <div id="tb" style="padding: 5px; height: auto">
        <div style="margin-bottom: 5px">
            商户名称：<input id="MerName" class="easyui-combobox" style="width: 200px" />
            <hr style="margin-top: 5px" />
            <div id="sleaccount" style=" display: none">
                查询条件：
			流水类型:&nbsp;<select id="MerAccType" class="easyui-combobox" style="width: 200px" editable="false">
                <option value="">全部</option>
                <option value="0">金额流水</option>
                <option value="1">第三方流水</option>
                <option value="2">积分流水</option>
                <option value="4">企业流水</option>
            </select>&nbsp;
            账目日期:&nbsp;<input id="MerAccDate" class="easyui-datebox" style="width: 120px">&nbsp;
			<a href="#" class="easyui-linkbutton" onclick="Search()" iconcls="icon-search">查询</a>
            </div>
        </div>
    </div>
    <!--工具栏E-->
</body>
</html>
